clear all; close all; clc;
%������ ��������� �������
R = 120;%��
C =33e-12/2;%��
RC=R*C;%���������� ������� ����
%��� �������
Tmod = 10*RC
T = RC / 1000;
t = 0:T:Tmod;
%�������� ������
U = nan(1, length(t));
dU = nan(1, length(t));
E  = 0*(t<Tmod/4) + 3*(t>=Tmod/4);
%������ ��������� ��������� 
U(1) = E(1); dU(1) = 0;
%% ���
fmin = 1/ (Tmod/2);
fmax = 2 *  (1/ RC /  2 / pi);
f = fmin:((fmax-fmin)/100):fmax;
A = 1;
K = nan(1, length(f));
for j = 1:length(f)
    E  = A*sin(2*pi*f(j)*t);
    
    U = nan(1, length(t));
    dU = nan(1, length(t));
    
    U(1) = E(1); dU(1) = 0;
    
    for k = 2:length(t)
        U(k) = (RC*U(k-1) + E(k)*T) / (RC + T);
    end
    U=U/2;
    Us = U(fix(end/2):end);
    K(j) = (max(Us) - min(Us)) / 2;
end

figure;
plot(f, 20*log10(K))
xlabel('f, Hz');
ylabel('K, dB');
grid on
figure;
plot(f, K)
xlabel('f, Hz');
ylabel('K');
grid on




